local hx__dengfeng = fk.CreateSkill({
  name = "hx__dengfeng",
})

hx__dengfeng:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__dengfeng.name) and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player,{
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "#hx__dengfeng-choose",
      skill_name = hx__dengfeng.name
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    ---@type string
    local skillName = hx__dengfeng.name
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local choices = { "hx__dengfeng_equip", "hx__dengfeng_slash", "hx__dengfeng_beishui" }
    local choice = choices[2]
    if #to:getCardIds("e") > 0 then
      choice = room:askToChoice(player, { choices = choices, skill_name = skillName })
    end
    if choice == "hx__dengfeng_beishui" then
      room:loseHp(player, 1, skillName)
    end
    if choice ~= "hx__dengfeng_slash" and #to:getCardIds("e") > 0 then
      local cards = room:askToChooseCards(player, { target = to, min = 1, max = 4, flag = "e", skill_name = skillName })
      room:obtainCard(to, cards, true, fk.ReasonPrey, to, skillName)
    end
    if choice ~= "hx__dengfeng_equip" and player:isAlive() then
      local ids = room:getCardsFromPileByRule("slash")
      if #ids > 0 then
        room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skillName, { "@@klmou__dengfeng-inhand", 1})
      end
    end
  end,
})

hx__dengfeng:addEffect(fk.PreCardUse, {
  can_refresh = function(self, event, target, player, data)
    return data.card and data.card:getMark("@@klmou__dengfeng-inhand") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.extraUse = true
  end,
})

hx__dengfeng:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and card:getMark("@@klmou__dengfeng-inhand") > 0
  end,
})


return hx__dengfeng
